package edu.njfu.sas.servlet;

import com.google.gson.Gson;
import edu.njfu.sas.dao.impl.StudentDaoImpl3;
import edu.njfu.sas.model.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

@WebServlet("/UpdateStudent" )
public class UpdateStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        String stuNo=request.getParameter("stuNo");
        String stuName=request.getParameter("stuName");
        String classes=request.getParameter("classes");
        String gender=request.getParameter("gender");
        String department=request.getParameter("department");
        String tel=request.getParameter("tel");
        String dormno=request.getParameter("dormno");
        String photopath=request.getParameter("photopath");
        Student student=new Student(stuNo,stuName,classes,gender,department,tel,dormno,photopath);
        System.out.println(student.toString());
        StudentDaoImpl3 studentDao=new StudentDaoImpl3();
        boolean result=studentDao.updateStudent(student);
        HashMap<String,String> map=new HashMap<String, String>();
        if(result){
            map.put("result","更改成功");
            map.put("msg","ok");
        }else{
            map.put("result","更改失败");
            map.put("msg","error");
        }
        PrintWriter out=response.getWriter();
        out.write(new Gson().toJson(map));

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
